<template>
  <el-dialog
    title="详情"
    :visible.sync="dialogVisible"
    width="50%"
    :before-close="handleClose"
  >
    <el-button
      type="primary"
      icon="el-icon-download"
      style="margin-bottom: 10px"
      @click="handleExport"
      >导出EXCEL</el-button
    >
    <el-table v-loading="loading" :data="list" style="width: 100%">
      <el-table-column
        v-for="(item, index) in columns"
        :key="index"
        prop="num"
        :label="item.label"
        width="150"
      />
      <!-- <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['msg:dcwjTk:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            v-hasPermi="['msg:dcwjTk:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>
    <pagination
      v-show="false"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { getDetail } from "@/api/earlyWarning/byxzrs";
import { getDicts as getDicts } from "@/api/system/dict/data";
export default {
  dicts: ["user_type"],
  props: ["dictType"],
  data() {
    return {
      dialogVisible: false,
      total: 0,
      list: [],
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      columns: [],
      dictList: [],
    };
  },
  mounted() {
    console.log(this.dictType);
    getDicts(this.dictType).then((response) => {
      this.dictList = response.data;
    });
  },
  methods: {
    openModal(checkList) {
      this.dialogVisible = true;
      this.getList();
      this.getColumns(checkList);
    },
    getList() {
      this.loading = true;
      getDetail().then((response) => {
        this.loading = false;
        this.list = response.data;
      });
    },
    getColumns(checkList) {
      const newColums = [];
      console.log(checkList);
      console.log(this.dictList);
      if (this.dictList.length > 0) {
        for (let i = 0; i < checkList.length; i++) {
          const item = this.dictList.find((v) => v.dictValue == checkList[i]);
          if (item) {
            newColums.push({
              label: item.dictLabel,
            });
          }
        }
      }
      console.log(this.columns);
      this.columns = newColums;
    },
    handleClose(done) {
      done();
    },
    handleExport() {
      this.download(
        "warn/sjsk/byxzrs/export",
        {},
        `详情_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
